package ioperation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        System.out.println("图书返还");
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输如你要归还的书名");
        String name=scanner.nextLine();
        int currentSize= bookList.getUsedSize();
        int i=0;
        for(;i<currentSize;i++){
            Book book=bookList.getBook(i);
            if(book.getName().equals(name)){
                if(book.isBorrowed()){
                    //isBorrowed为true时，表示书以经借出
                    book.setBorrowed(false);
                    //将isBorrowed的值变为false，代表书归还
                    System.out.println("归还成功");
                    return;
                }
            }
        }
        //跳出循环则代表没有要归还的图书
        System.out.println("没有你想要归还的图书");
        return;
    }
}
